home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2006 May / PCpro_2006_05.ISO / files / mobile / fma-2.0-stable-setup.exe / {app} / sframework / plugins / VLCPLayer.vbs < prev    next >
Encoding:
Text File  |  2004-10-27  |  6.4 KB  |  233 lines

  1. 'Controls the VLC Player
  2.  
  3. Class VLCPLayer
  4.  
  5. Private m_Self 'Reference to myself
  6. Private mainMenu 'The menu
  7. Private isFullscreen 'if true the app is fullscreen and should not be tested for foreground
  8.          'running, we take VLC player starts up not fullscreen default
  9.  
  10. Private hkPlay, hkStop, hkFullscreen, hkVolumeUp, hkVolumeDown, hkMute, hkFwd, hkBwd 'Constants expressing the shortcut key for each action
  11. Private isPressed 'True if the key is still pressed
  12.  
  13. 'Some info about the plugin
  14. Public Property Get SHOWABLE 'Do I have a menu?
  15.  SHOWABLE    = True
  16. End Property
  17. Public Property Get TITLE 'What's my name?
  18.  TITLE       = "VLCPlayer"
  19. End Property
  20. Public Property Get DESCRIPTION 'What's my purpose?
  21.  DESCRIPTION = "Lets you control VLS Player"
  22. End Property
  23. Public Property Get AUTHOR 'Who created me?
  24.  AUTHOR      = "ChoKamir"
  25. End Property
  26.  
  27. 'Who am I?
  28. Public Property Let Self (s)
  29.  m_Self = s
  30.  ' Some init stuff here:
  31.  If IsEmpty(Settings(Me, "Title")) or Settings(Me, "Title") = "" Then Settings(Me, "Title") = "VLC Media Player"
  32.  If IsEmpty(Settings(Me, "Exe"))   or Settings(Me, "Exe")   = "" Then Settings(Me, "Exe")   = "C:\Program Files\VideoLAN\VLC\vlc.exe"
  33.  
  34.  'Sets the shortcuts
  35.  hkPlay = " "
  36.  hkStop = "s"
  37.  hkFullscreen = "f"
  38.  hkVolumeUp = "^{up}"
  39.  hkVolumeDown = "^{down}"
  40.  hkMute = "m"
  41.  hkFwd = "%{right}"
  42.  hkBwd = "%{left}"
  43.  isFullscreen = false
  44.  
  45.  'Sets the menu
  46.  Set mainMenu = New ManagedMenu
  47.  mainMenu.Title = TITLE
  48. End Property
  49. Public Property Get Self
  50.  Self = m_Self
  51. End Property
  52.  
  53. 'Display me. Eventually put a menu on the screen
  54. Sub Show()
  55.  Dim llist
  56.  '--> Init Menu
  57.  Set llist = New LinkedList
  58.  Dim bi
  59.  bi = llist.BackInserter
  60.  'Creates the menu
  61.  If VLCPlayerOpen Then
  62.   bi.Item = Array("Play/Pause",    Self & ".Play")
  63.   bi.Item = Array("Stop",          Self & ".Stopp")
  64.   bi.Item = Array("Fullscreen",    Self & ".Fullscreen")
  65.   bi.Item = Array("(Un)Mute",      Self & ".Mute")
  66.   bi.Item = Array("Close",         Self & ".Close")
  67.  Else
  68.   bi.Item = Array("Launch",        Self & ".Launch")
  69.  End If
  70.  
  71.  'makes sure we know when we are kicked out for proper clean up
  72.  EventManager.RegisterEvent "MenuClose",      Self & ".ExitMenu", Me
  73.  EventManager.RegisterEvent "ConnectionLost", Self & ".ExitMenu", Me
  74.  
  75.  'Registers the key actions used for volume
  76.  KeyManager.RegisterKey   KEY_VOLUP,  Self & ".VolumeUp" , STATE_PRESS  , Me
  77.  KeyManager.RegisterKey   KEY_VOLDOWN,  Self & ".VolumeDown", STATE_PRESS  , Me
  78.  KeyManager.RegisterKey   KEY_VOLUP,  Self & ".Released", STATE_RELEASE  , Me
  79.  KeyManager.RegisterKey   KEY_VOLDOWN,  Self & ".Released",  STATE_RELEASE  , Me
  80.  
  81.  'Registers the key actions used
  82.  KeyManager.RegisterKey   KEY_JOYRIGHT,  Self & ".Forward" , STATE_PRESS  , Me
  83.  KeyManager.RegisterKey   KEY_JOYLEFT,  Self & ".Backward", STATE_PRESS  , Me
  84.  KeyManager.RegisterKey   KEY_JOYRIGHT,  Self & ".Released", STATE_RELEASE  , Me
  85.  KeyManager.RegisterKey   KEY_JOYLEFT,  Self & ".Released", STATE_RELEASE  , Me
  86.  
  87.  'Shows the menu
  88.  mainMenu.SetList llist
  89.  mainMenu.ShowMenu
  90.  
  91.  If VLCPlayerOpen Then
  92.   'makes sure we show an empty menu so when we return form the msgbox we come back to the original menu
  93.   EmptyMenu.ShowMenu
  94.   am.DlgMsgBox "Use the phone volume keys to change volume and joystick(left/right) to skip forward/backward", 0
  95.  End if
  96. End Sub
  97.  
  98. 'Function returns true if the VLCPlayer is open(foregrounded)
  99. Function VLCPlayerOpen
  100.  'Checks if we are running fullscreen, otherwise with overlaying the window will come in front
  101.  If isFullscreen Then
  102.   VLCPlayerOpen = True
  103.  Else
  104.   'Not in fullscreen so check if we can activate the app
  105.   VLCPlayerOpen = Shell.AppActivate(Settings(Me, "Title"))
  106.  End if
  107. End Function
  108.  
  109. 'Triggered when the user click play
  110. Sub Play
  111.  If VLCPlayerOpen Then Shell.SendKeys hkPlay
  112.  am.Update
  113. End Sub
  114.  
  115. 'Triggered when the user click stop
  116. Sub Stopp
  117.  If VLCPlayerOpen Then Shell.SendKeys hkStop
  118.  am.Update
  119. End Sub
  120.  
  121. 'Triggered when the user click fullscreen
  122. Sub Fullscreen
  123.  If VLCPlayerOpen Then
  124.   Shell.SendKeys hkFullscreen
  125.   'changes the state of fullscreen
  126.   isFullscreen = Not isFullscreen
  127.   am.Update
  128.  End if
  129. End Sub
  130.  
  131. 'Triggered when the user releases the joystick so we can stop changing the volume
  132. Sub Released
  133.  isPressed = False
  134. End Sub
  135.  
  136. 'Triggered when the user presses the button to make the volume go up
  137. Sub VolumeUp
  138.  If VLCPlayerOpen Then 
  139.   'Sets that the joystick is pressed
  140.   isPressed = True
  141.   'loops till the user releases the joystick
  142.   While isPressed
  143.    'makes the volume go up
  144.    Shell.SendKeys hkVolumeUp
  145.    'waits 100ms
  146.    Util.sleep(100)
  147.   Wend 
  148.  End if
  149. End Sub
  150.  
  151. 'Triggered when the user presses the button to make the volume go up
  152. Sub VolumeDown
  153.  If VLCPlayerOpen Then 
  154.   'Sets that the joystick is pressed
  155.   isPressed = True
  156.   'loops till the user releases the joystick
  157.   While isPressed
  158.    'makes the volume go up
  159.    Shell.SendKeys hkVolumeDown
  160.    'waits 100ms
  161.    Util.sleep(100)
  162.   Wend 
  163.  End if
  164. End Sub
  165.  
  166. 'Triggered when the user click Mute
  167. Sub Mute
  168.  If VLCPlayerOpen Then Shell.SendKeys hkMute
  169.  am.Update
  170. End Sub
  171.  
  172. 'Triggered when the user moves the joystick to go forward
  173. Sub Forward
  174.  If VLCPlayerOpen Then 
  175.   'Sets that the joystick is pressed
  176.   isPressed = True
  177.   'loops till the user releases the joystick
  178.   While isPressed
  179.    'makes the volume go up
  180.    Shell.SendKeys hkFwd
  181.    'waits 100ms
  182.    Util.sleep(500)
  183.   Wend 
  184.  End if
  185. End Sub
  186.  
  187. 'Triggered when the user moves the joystick to go backward
  188. Sub Backward
  189.  If VLCPlayerOpen Then 
  190.   'Sets that the joystick is pressed
  191.   isPressed = True
  192.   'loops till the user releases the joystick
  193.   While isPressed
  194.    'makes the volume go up
  195.    Shell.SendKeys hkBwd
  196.    'waits 100ms
  197.    Util.sleep(500)
  198.   Wend 
  199.  End if
  200. End Sub
  201.  
  202. 'Triggered when the user wants to close the VLC player
  203. Sub Close
  204.  If VLCPlayerOpen Then 
  205.   Shell.SendKeys "%{F4}"
  206.   Util.Sleep 3000 
  207.  End If
  208.  Show
  209. End Sub
  210.  
  211. 'Triggered when the user wants to launch the player
  212. Sub Launch
  213.  If Fso.FileExists(Settings(Me, "Exe")) Then
  214.   Shell.Exec Settings(Me, "Exe")
  215.   Util.WaitForAppLoad Settings(Me, "Title"),10000
  216.  Else
  217.   Debug.ErrorMsg Self & " - Launch: File not found: " & Settings(Me, "Exe")
  218.  End If
  219.  Show
  220. End Sub
  221.  
  222. 'Triggered when we left a menu
  223. Sub ExitMenu ( sName )
  224.  Debug.debugmsg "Exit" + sname
  225.  'Checks if that was the VLS main menu
  226.  If sName = TITLE Then
  227.   'Makes a clear exit
  228.   KeyManager.DeregisterAll Me
  229.   EventManager.DeregisterAll Me
  230.  End If
  231. End sub
  232. End Class
  233.